<!doctype html>
<html>
    
    <body>
        <h1>IframeBridge</h1>
        <div id='buttons'></div>
        
        <script>
            var callback;
            
            // 调用原生代码
            function callNative(action, data, responseCallback) {
                callback = responseCallback;
                var iframe = document.createElement('iframe');
                iframe.style.display = 'none';
                iframe.src = 'https://__jsbridge__?action=' + action + '&data=' + data;
                document.documentElement.appendChild(iframe);
            }
        
        // 暴露给原生，接收调用结果
        function responseFromObjC(response) {
            if (!callback) {
                return;
            }
            callback(response);
        }
        
        // 调用demo
        ; (function () {
           var callbackButton = document.getElementById('buttons').appendChild(document.createElement('button'));
           callbackButton.innerHTML = 'CallNative';
           callbackButton.onclick = function (e) {
           callNative("alertMessage", "Hello world!", function (response) {
                      alert(response);
                      });
           };
           })()
           
            </script>
    </body>
    
</html>
